//
//  KKBaseAFNetWorking.h
//  AFnetWorking测试
//
//  Created by long on 14-11-18.
//  Copyright (c) 2014年 谭启龙. All rights reserved.
//  网络加载的根类

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "CMCometNetWorking.h"
#import "XLBaseNetMode.h"
typedef enum : NSUInteger{
	XLRequestMethodGet = 0,
	XLRequestMethodPost = 1,           // content type = @"application/x-www-form-urlencoded"
} XLRequestMethod;

#define KKCancelLoad @"KKCancelLoad"//取消网络加载的通知

typedef void(^sucBlock)(XLBaseNetMode * resulte); //请求成功的参数
typedef void(^errorBlock)(id resulte);//请求失败的参数
typedef void(^cancelBlock)();//取消请求的参数

@interface XLBaseAFNetWorking : NSObject
@property (nonatomic,copy) sucBlock sucBlock;
@property (nonatomic,copy) errorBlock errorBlock;
@property (nonatomic,copy) cancelBlock cancelBlock;
@property (nonatomic,strong) id result; //json解析出的字典
@property (nonatomic,copy) NSString * requestUrl;

//网络请求
-(id)initWithParameters:(NSMutableDictionary *)dic IndicatorView:(UIView *)view LoadingFinished:(sucBlock)sucBlock CancelLoading:(cancelBlock)cancelBlock LoadingError:(errorBlock)errorBlock;

-(id)initWithUrl:(NSString *)url Parameters:(NSMutableDictionary *)dic IndicatorView:(UIView *)view LoadingFinished:(sucBlock)sucBlock CancelLoading:(cancelBlock)cancelBlock LoadingError:(errorBlock)errorBlock;

//请求成功和失败走的方法
-(void)sucBlockDo:(id)resulte;
-(void)errorBlockDo:(id)resulte;

/**
 *  网络加载的缓冲图标
 *
 *  @param superView 要加载到哪个视图上
 */
-(void)loadMaskAcivityView:(UIView *)superView;

/**
 *  数据加工处理
 *
 *  @param resultDic 请求成功后的数据
 *
 *  @return 处理后的数据
 */
-(XLBaseNetMode *)processResult:(id)result;

/**
 *  获取网络加载方式
 *
 *  @return KKRequestMethod类型的
 */
- (XLRequestMethod)getRequestMethod;

/**
 *  获取接口的地址
 *
 *  @return 要获取数据的地址，可以带问号也可以不带问号加参数
 */
- (NSString*)getRequestUrl;

/**
 *  取消网络访问
 */
-(void)cancle;

@end

@interface XLBaseAFNetWorking (comet)
@property (nonatomic,strong) CMCometNetWorking * cometNet; //comet连接
//comet连接服务器
-(id)initCometWithParam:(NSDictionary *)dic LoadingFinished:(sucBlock)sucBlock Error:(errorBlock)errorBlock;

//暂停
-(void)suspend;
//启动
-(void)resume;
//取消访问
-(void)cancel;
@end

@interface XLBaseAFNetWorking (native)
/**
 *  加载之前先查看本地本地,有则不发起网络请求
 *
 *  @param dic         参数
 *  @param view        缓冲图
 *  @param sucBlock    成功后的回调
 *  @param cancelBlock 取消的回调
 *  @param errorBlock  失败后的回调
 *
 *  @return 类本身(建议在网络访问期间持有)
 */
-(id)initNativeWithParameters:(NSMutableDictionary *)dic IndicatorView:(UIView *)view LoadingFinished:(sucBlock)sucBlock CacelLoading:(cancelBlock)cancelBlock LoadingError:(errorBlock)errorBlock;

/**
 *  加载之前先查看本地本地,有则先使用本地的再访问网络的
 *
 *  @param dic         参数
 *  @param view        缓冲图
 *  @param sucBlock    成功后的回调
 *  @param cancelBlock 取消的回调
 *  @param errorBlock  失败后的回调
 *
 *  @return 类本身(建议在网络访问期间持有)
 */
-(id)initNativeAndNetWithParameters:(NSMutableDictionary *)dic IndicatorView:(UIView *)view LoadingFinished:(sucBlock)sucBlock CacelLoading:(cancelBlock)cancelBlock LoadingError:(errorBlock)errorBlock;
@end
